package mybatis1.com.config.dao;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybitsUtil {
    public static String resource;

    static {
        resource = "mybatis1/com/config/config.xml";
    }

    public static SqlSession getSqlSession() {
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            return sqlSessionFactory.openSession();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static void close(SqlSession sqlSession){
        sqlSession.close();
    }
    public static void commit(SqlSession sqlSession){
        sqlSession.commit();
    }
}